<template>
    <div>
        <div class="container">
            <div class="nav">
                <div class="nav_wrap">
                    <div class="quit" @click="$router.back()"></div>
                    <div class="subnav">
                        评论
                    </div>
                    <div class="nav_icon">
                        <router-link tag="a" to="/shelf"></router-link>
                        <i v-show="!isTop" @click="topShow"></i>
                        <i class="topnav" v-show="isTop" @click="topShow"></i>
                    </div>
                </div>
            </div>
            <div class="wrap" v-show="isTop" @click.self="topShow">
                <div class="subnav">
                    <ul>
                        <router-link tag="li" to="/">
                            <img src="../assets/images/tp_1.png" alt="">
                            <span>首页</span>
                        </router-link>
                        <router-link tag="li" to="/library">
                            <img src="../assets/images/tp_02.png" alt="">
                            <span>书库</span>
                        </router-link>
                        <router-link tag="li" to="/shelf">
                            <img src="../assets/images/tp_03.png" alt="">
                            <span>书架</span>
                        </router-link>
                        <router-link tag="li" to="/user">
                            <img src="../assets/images/tp_04.png" alt="">
                            <span>账户</span>
                        </router-link>
                        <router-link tag="li" to="/pay">
                            <img src="../assets/images/tp_05.png" alt="">
                            <span>充值</span>
                        </router-link>
                        <router-link tag="li" to="/search">
                            <img src="../assets/images/tp_06.png" alt="">
                            <span>搜索</span>
                        </router-link>
                    </ul>
                </div>
            
            </div>
            <!-- 文本框 -->
            <div class="word bor_bot">
                <div class="addto">
                    <textarea placeholder="有深度的评论，我也来说两句……" v-model="comval"></textarea>
                </div>
                <div class="emote">
                    <span>表情</span>
                    <ul>
                        <li></li>
                    </ul>
                </div>
                <div class="addgo" @click="addto()">
                    提交评论
                </div>
            </div>

            <!-- 评论 -->
            <div class="comment bor_bot">
                <div class="comment_tit">
                    <span v-if="comment">评论 <em>({{ comment.length }})</em></span>
                    <em></em>
                </div>
                <div class="comment_cont">
                    <ul v-if="comment">
                        <li v-for="(item) in comment" :key="item.posttime">
                            <div class="author">
                                <img src="../assets/images/user.png" alt="">
                            </div>
                            <div class="com_major">
                                <h2>{{item.username}}</h2>
                                <p>{{ item.text }}</p>
                                <div class="time">
                                    {{ item.posttime }}
                                    <a href="javascript:;" @click="addto()"></a>
                                </div>
                                <div class="listCom" v-if="item.replied">
                                    <div class="list_head">
                                        <div class="list_name">{{ item.replied.username }}</div>
            
                                        <div class="time">
                                            {{ item.replied.posttime }}
                                        </div>
                                    </div>
                                    <div class="list_cont">
                                        {{ item.replied.text}}
                                    </div>
                                </div>
                            </div>
                        </li>
                    </ul>
                    <div class="com_more" @click="$toast('没有更多评论了')">
                        更多评论
                        <img src="../assets/images/timeJt.png" alt="">
                    </div>
                </div>
            </div>

            <!-- 搜索框 -->
            <router-link tag="div" to="/search" class="search">
                <div class="search_wrap">
                    <input type="text">
                    <button></button>
                </div>
            </router-link>
            <!-- 页脚信息 -->
            <div class="footer">
                <div class="foot_tit">
                    <ul>
                        <li>
                            <a href="javascript:;">首页</a>
                        </li>
                        <li>
                            <a href="javascript:;">书库</a>
                        </li>
                        <li>
                            <a href="javascript:;">书架</a>
                        </li>
                        <li>
                            <a href="javascript:;">账户</a>
                        </li>
                        <li>
                            <a href="javascript:;">客户端</a>
                        </li>
                    </ul>
                </div>
                <div class="foot_cont">
                    <div class="foot_info">
                        <p>客服QQ群：326738643</p>
                        <p>客服电话：010-86462015-800</p>
                        <p>©2020北京爱书客科技有限公司</p>
                        <p>京ICP备13037522号</p>
                    </div>
                    <div class="info_img">
                        <img src="../assets/images/ledu.png" alt="">
                        <span>乐读书城</span>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
import { getCommentData } from '../api/comment';
    export default {
    data() {
        return {
            isTop: false,//判断子菜单的展示
            comment: null,//评论数据
            comval:'',//评论内容
            bool:false,//判断是回复其他评论还是发表自己的评论
            num:0,//记录回复的是哪条评论
        }
    },
    methods: {
        topShow() {
            this.isTop = !this.isTop
        },
        addto(num){
            let val = this.comval;
            if(val == ''){
                this.$toast('内容空白')
                return
            }

            let time = new Date();
            let y = time.getFullYear();
            let m = time.getMonth();
            let d = time.getDate();
            let day = y + '-' + m + '-' + d;
            if(num != undefined){
                this.comment[num].replied = {
                    posttime: day,
                    text:val,
                    username:'本人'
                }
                console.log(this.comment[num].replied);
            }else{
                this.comment.push({
                    posttime:day,
                    text:val,
                    username:'本人'
                })
            }
            this.comval = ''
        },
        // dialog(num,e){
        //     this.bool = !this.bool;
        //     this.num = num;
        //     console.log(e.target);
        //     e.target.classList.toggle('col');
        // }
    },
    created() {
        getCommentData().then(data => {
            this.comment = data.data.data
            console.log(this.comment);
        })
    },
    }
</script>

<style lang="scss" scoped>
.nav {
    padding: 0 14px;
    border-bottom: 1px solid #e0e0e0;

    .nav_wrap {
        display: flex;
        align-items: center;
        justify-content: space-between;

        .quit {
            width: 10px;
            height: 45px;
            background-image: url('../assets/images/quit.png');
            background-repeat: no-repeat;
            background-size: 100%;
            background-position: center;
        }

        .subnav {
            padding-left: 66px;

            &>ul {
                display: flex;
                width: 138px;
                height: 26px;
                margin: auto;
                border-radius: 13px;
                background-color: #f0f0f0;
                overflow: hidden;

                &>li {
                    flex: 1;
                    text-align: center;
                    color: #000;
                    height: 26px;
                    line-height: 26px;
                }

                &>.con {
                    background-color: #ea4136;
                    color: #fff;
                    border-radius: 13px;
                }
            }
        }

        span {
            color: #333;
            font-size: 16px;
            display: block;
            text-align: center;
            line-height: 45px;
            width: 54%;
            padding-left: 70px;
        }

        .nav_icon {
            display: flex;
            align-items: center;
            justify-content: space-between;
            width: 80px;

            a {
                display: block;
                width: 25px;
                height: 22px;
                background-image: url('../assets/images/book_ico1.png');
                background-repeat: no-repeat;
                background-size: 100%;
                background-position: center;
                
            }

            i {
                display: block;
                width: 20px;
                height: 20px;
                background-image: url('../assets/images/bookMore_ico1.png');
                background-size: 100%;
                background-position: center;

            }

            .topnav {
                background-image: url('../assets/images/tp_close.png');
            }
        }
    }
}

.wrap {
    position: fixed;
    top: 45px;
    bottom: 0;
    left: 0;
    right: 0;
    background-color: rgba(0, 0, 0, .8);

    .subnav {
        width: 100%;
        background-color: #fff;
        padding-bottom: 18px;

        ul {
            display: flex;
            flex-wrap: wrap;

            li {
                width: 25%;
                text-align: center;
                padding-top: 20px;

                img {
                    width: 40px;
                    height: 40px;
                    margin: 0 auto 8px auto;
                }

                span {
                    font-size: 13px;
                    color: #666;
                }
            }
        }
    }

}

.word{
    padding: 14.5px;
    .addto{
        &>textarea{
            padding: 9px;
            display: block;
            width: 328px;
            height: 50px;
            resize: none;
            border: 0px;
        }
        padding-bottom: 10px;
    }
    .emote{
        &>span{
            display: block;
            height: 21px;
            padding-left: 26px;
            margin: 12px 0;
            background-image: url('../assets/images/faceIcon.png');
            background-repeat: no-repeat;
            background-position: left center;
            background-size: 20px;
            font-size: 14px;
            color: #777;
        }
    }
    .addgo{
        height: 43px;
        border-radius: 21px;
        background-color: #ea4136;
        font-size: 16px;
        line-height: 43px;
        margin-top: 20px;
        text-align: center;
        color: #fff;
        
    }
}

.comment {
    padding: 0 14px;

    .comment_tit {
        padding-left: 8px;
        height: 52px;
        line-height: 52px;
        border-bottom: 1px solid #ebebeb;
        background-image: url('../assets/images/daohang_redIco.jpg');
        background-repeat: no-repeat;
        background-position: left center;
        background-size: 4px;
        display: flex;
        justify-content: space-between;

        span {
            font-size: 16px;
            color: #333;
        }

        em {
            color: #999;
            font-size: 15px;
            font-style: normal;
        }
    }

    .comment_cont {
        ul {
            li {
                display: flex;

                .author {
                    img {
                        width: 37px;
                        height: 37px;
                        margin: auto;
                    }
                }

                .com_major {
                    width: 86%;
                    padding: 0 0 17px 12px;

                    h2 {
                        font-size: 16px;
                        color: #333;
                        height: 37px;
                        line-height: 37px;
                    }

                    p {
                        font-size: 15px;
                        color: #595959;
                        padding: 6px 0 14px 0;
                    }

                    .time {
                        font-size: 13px;
                        color: #999;
                        display: flex;
                        justify-content: space-between;

                        a {
                            width: 20px;
                            height: 16px;
                            display: block;
                            background-image: url('../assets/images/commentIco.png');
                            background-repeat: no-repeat;
                            background-size: 90%;
                        }
                    }

                    .listCom {
                        padding: 15px 11px;
                        background-color: #fafafa;
                        margin-top: 14px;

                        .list_head {
                            padding-left: 8px;
                            height: 25px;
                            line-height: 25px;
                            background-image: url('../assets/images/daohang_redIco.jpg');
                            background-repeat: no-repeat;
                            background-position: -1px center;
                            background-size: 3px;
                            display: flex;
                            justify-content: space-between;

                            .list_name {
                                font-size: 16px;
                                color: #333;
                            }

                            .time {
                                color: #999;
                                font-size: 13px;
                            }
                        }

                        .list_cont {
                            padding: 12px 0 0 8px;
                            font-size: 12px;
                            color: #999;
                        }
                    }
                }
            }
        }

        .com_more {
            font-size: 15px;
            color: #999;
            padding: 11px 0;
            display: flex;
            justify-content: center;
            align-items: center;
            border-top: 1px solid #ebebeb;

            img {
                width: 9px;
                margin-left: 5px;
            }
        }
    }
}
.bor_bot {
    border-bottom: 10px solid #eaeaea;
}
.search {
    padding: 10px 14px;

    .search_wrap {
        display: flex;
        padding: 4px 0 4px 17px;
        border: 1px solid #dbdbdb;
        height: 32px;
        border-radius: 20px;
        overflow: hidden;

        &>input {
            border: 0px;
            outline: none;
            flex: 6;
            color: #999;
        }

        &>button {
            flex: 1;
            background-image: url('../assets/images/searchBar.png');
            background-repeat: no-repeat;
            border: 0px;
            background-color: #fff;
            position: relative;
            border-left: 1px solid #dbdbdb;
            background-size: 18px;
            background-position: center;
        }
    }
}
.footer {
    padding: 16px 0px 32px 0px;
    background-color: #1c1a1a;

    .foot_tit {
        padding-bottom: 15px;

        ul {
            display: flex;

            li {
                flex: 1;

                a {
                    display: block;
                    font-size: 16px;
                    color: #b6b6b6;
                    text-align: center;
                    border-right: 1px solid #999999;

                }

                &:last-of-type {
                    a {
                        border: 0px;
                    }
                }
            }
        }
    }

    .foot_cont {
        display: flex;
        justify-content: space-between;
        padding: 0 16px;

        .foot_info {
            p {
                color: #b6b6b6;
                font-size: 12px;
                line-height: 28px;
            }
        }

        .info_img {
            img {
                width: 98px;
                height: 98px;
            }

            span {
                font-size: 12px;
                display: block;
                text-align: center;
                color: #b6b6b6;
                padding-top: 3px;
            }
        }
    }
}
</style>